package com.chx.three.mama.task;

import android.os.AsyncTask;

import com.chx.three.mama.utils.HttpTool;
import com.chx.three.mama.utils.TaskProcessor;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

/**
 * Created by Hainuo on 2015/3/22.
 */
public class ActionListTask extends AsyncTask<String,Integer,JSONObject>{
    private TaskProcessor processor;

    public ActionListTask(TaskProcessor processor) {
        this.processor = processor;
    }

    @Override
    protected JSONObject doInBackground(String... params) {
        JSONObject ret = null;

        String url = "http://www.qubaobei.com/ios/api/city_act_list.php?user_id=4587968&mobile_id=61&m_plat=61&m_site=2";

        byte[] bytes = HttpTool.get(url);

        if(bytes != null){
            try {
                String str = new String(bytes,"UTF-8");
                ret = new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }catch (JSONException e){
                e.printStackTrace();
            }
        }

        return ret;
    }

    @Override
    protected void onPostExecute(JSONObject jsonObject) {
        processor.processResult(jsonObject);
    }
}
